public class BinarySearch {
    public static void main(String[] args) {
        int[] arr = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19};
        int key = 15;
        int index = binarySearch(arr, key);
        if (index == -1) {
            System.out.println("Element not found");
        } else {
            System.out.println("Element found at index " + index);
        }
    }

    public static int binarySearch(int[] arr, int key) {
        int l, m, r;
        l = 0;
        r = arr.length - 1;
        m = l + (r - l) / 2;
        while (l <= r) {
            if (arr[m] < key) {
                l = m + 1;
            } else if (arr[m] > key) {
                r = m - 1;
            } else {
                return m;
            }
            m = l + (r - l) / 2;
        }
        return -1;
    }
}
